package com.qf;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class config {
    @Pointcut("execution(* com.qf.service.impl.*.*(..))")
    public void pc(){}

    @Before("pc()")
    public void before(){
        System.out.println("前置");
    }
    @After("pc()")
    public void after(){
        System.out.println("后置");
    }

    @AfterThrowing("pc()")
    public void MyThrows(){
        System.out.println("异常");
    }

    @Around("pc()")
    public Object myInterceptor(ProceedingJoinPoint proceedingJoinPoint){
        try {
            System.out.println("前置");
            Object proceed = proceedingJoinPoint.proceed();
            System.out.println("后置");
            return proceed;
        } catch (Throwable throwable) {
            throwable.printStackTrace();
            System.out.println("异常");
            throw new  RuntimeException("捕获异常");
        } finally {
            System.out.println("最终");
        }

    }
}
